<template>
  <div class="container">
    <el-skeleton class="shop-header" :loading="loading">
      <div class="shop-header-skeleton" slot="template">
        <edu-image class="image"></edu-image>
        <div class="intro">
          <el-skeleton-item variant="h1" class="title" />
          <el-skeleton-item variant="rect" class="rect" />
          <el-skeleton-item variant="p" class="txt" />
          <el-skeleton-item variant="p" class="txt" />
          <el-skeleton-item variant="button" class="button" />
        </div>
      </div>
      <div>
        <div class="shop-header__product">
          <div class="product-image">
            <swiper class="banner-swiper" :options="swiperOption">
              <swiper-slide v-for="(item, index) in productInfo.swiper" :key="index">
                <img class="image" :src="item.fileurl" alt="" />
              </swiper-slide>
              <div class="swiper-pagination swiper-pagination-white" slot="pagination"></div>
              <div class="swiper-button-prev swiper-button-white" slot="button-prev"></div>
              <div class="swiper-button-next swiper-button-white" slot="button-next"></div>
            </swiper>
          </div>
          <div class="product-intro">
            <h2 class="title">{{ productInfo.title }}</h2>
            <div class="summary">
              <template v-if="productInfo.credit_price > 0 && productInfo.cash_price > 0">
                <span class="price">{{ productInfo.credit_price }}</span>
                <span class="txt">积分+{{ priceSymbol }}</span>
                <span class="price">{{ productInfo.cash_price }}</span>
              </template>
              <template v-else-if="productInfo.credit_price > 0">
                <span class="price">{{ productInfo.credit_price }}</span>
                <span class="txt">积分</span>
              </template>
              <template v-else-if="productInfo.cash_price > 0">
                <span class="txt">{{ priceSymbol }}</span>
                <span class="price">{{ productInfo.cash_price }}</span>
              </template>
              <span class="free" v-else>免费</span>
              <span class="pricing" v-if="productInfo.scribing_price > 0"
                >{{ priceSymbol }}{{ productInfo.scribing_price }}</span
              >
            </div>
            <div class="structuration">
              <span class="label">月兑换</span>
              <span class="num">{{ productInfo.month_count }}</span>
            </div>
            <div class="structuration">
              <span class="label">库存</span>
              <span class="num">{{ productInfo.stock_num }}</span>
            </div>
            <div class="btn-group">
              <button type="button" class="button" @click="handleProductPay">
                立即兑换
              </button>
            </div>
          </div>
        </div>
        <!-- <div class="shop-header__preview">
                    <el-link
                        class="item"
                        icon="edu-icon-fenxiang edu-icon--left"
                        :underline="false"
                        >分享</el-link
                    >
                    <el-link
                        class="item"
                        icon="edu-icon-saoma edu-icon--left"
                        :underline="false"
                        v-popover:popover
                        >扫码查看</el-link
                    >
                    <el-popover
                        ref="popover"
                        placement="bottom"
                        trigger="hover"
                    >
                        <el-row type="flex" justify="center">
                            <vue-qr
                                :text="wxpayQrcode"
                                :size="120"
                                :margin="0"
                            ></vue-qr>
                        </el-row>
                    </el-popover>
                </div> -->
      </div>
    </el-skeleton>

    <div class="shop-detail">
      <div class="title">商品详情</div>
      <div class="content">
        <el-skeleton :loading="loading" :rows="6" />
        <div v-if="!loading" v-html="productInfo.info"></div>
      </div>
    </div>
  </div>
</template>

<script>
// import vueQr from "vue-qr";
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import projectSetting from '@/settings/projectSetting.js'
import 'swiper/css/swiper.css'
export default {
  components: {
    // vueQr,
    Swiper,
    SwiperSlide
  },
  data() {
    return {
      priceSymbol: projectSetting.appMoneySymbol,
      swiperOption: {
        loop: true,
        effect: 'fade',
        pagination: {
          el: '.swiper-pagination',
          type: 'fraction'
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      },
      productInfo: {},
      loading: true
    }
  },
  methods: {
    getProductInfo() {
      this.$api.getMallProductDetails(this.$route.query.id, res => {
        const { data } = res
        this.productInfo = data
        setTimeout(() => {
          this.loading = false
        }, 50)
      })
    },
    handleProductPay() {
      this.$router.push({
        path: '/mall/pay',
        query: {
          id: this.productInfo.id
        }
      })
    }
  },
  created() {
    this.getProductInfo()
  }
}
</script>

<style lang="scss" scoped>
.shop-header-skeleton {
  display: flex;
  .image {
    width: 400px;
    height: 400px;
  }
  .intro {
    flex: 1;
    margin-left: 30px;
    display: flex;
    flex-direction: column;
  }
  .title {
    width: 310px;
  }
  .rect {
    height: 70px;
    margin-top: 30px;
  }
  .txt {
    width: 130px;
    margin-top: 30px;
  }
  .button {
    width: 94px;
    height: 36px;
    margin-top: auto;
  }
}
.shop-header {
  margin-top: 10px;
  padding: 26px 30px;
  background-color: #ffffff;
  &__product {
    display: flex;
    .product-image {
      width: 400px;
      --swiper-navigation-size: 20px;
      .image {
        width: 400px;
        height: 400px;
        display: block;
      }
      .swiper-pagination {
        left: auto;
        right: 15px;
        bottom: 15px;
        width: auto;
        height: 20px;
        padding: 0 10px;
        background: rgba(48, 49, 51, 0.4);
        border-radius: 11px;
        font-size: 14px;
        font-weight: 400;
        color: #ffffff;
        display: flex;
        align-items: center;
      }
      .swiper-button-prev,
      .swiper-button-next {
        width: 40px;
        height: 40px;
        background: rgba(48, 49, 51, 0.4);
        border-radius: 20px;
        font-weight: bold;
      }
      .swiper-button-prev {
        left: 15px;
      }
      .swiper-button-next {
        right: 15px;
      }
    }
    .product-intro {
      flex: 1;
      margin-left: 30px;
      display: flex;
      flex-direction: column;
      .title {
        font-size: 20px;
        font-weight: 500;
        color: $text-color-import;
        line-height: 30px;
        margin: 0;
        @include ellipsisLine(2);
      }
      .summary {
        height: 70px;
        padding: 18px 20px 0;
        margin-top: 30px;
        display: flex;
        align-items: baseline;
        box-sizing: border-box;
        border-radius: 4px;
        background-image: url('~@assets/images/mall/store_price_bg.png');
        .price {
          font-size: 25px;
          font-weight: bold;
          color: $text-color-price;
          line-height: 1;
        }
        .free {
          font-size: 22px;
          color: $text-color-free;
          line-height: 1;
        }
        .txt {
          font-size: 14px;
          font-weight: 500;
          color: $text-color-price;
        }
        .pricing {
          margin-left: 10px;
          font-size: 14px;
          font-weight: 400;
          color: $text-color-auxiliary;
          text-decoration: line-through;
        }
      }
      .structuration {
        font-size: 14px;
        font-weight: 400;
        color: #606266;
        margin-top: 30px;
        .label {
          width: 50px;
          margin-right: 10px;
        }
      }
      .btn-group {
        margin-top: auto;
        .button {
          display: inline-block;
          line-height: 1;
          white-space: nowrap;
          cursor: pointer;
          -webkit-appearance: none;
          box-sizing: border-box;
          outline: 0;
          margin: 0;
          transition: 0.1s;
          font-weight: 400;
          padding: 11px 19px;
          font-size: 14px;
          border-radius: 4px;
          color: #fff;
          border: 0;
          background: linear-gradient(90deg, #ff3b2f 0%, #ff8a52 100%);
        }
      }
    }
  }
  &__preview {
    display: flex;
    align-items: center;
    margin-top: 20px;
    .item {
      font-size: 12px;
      font-weight: 400;
      color: $text-color-auxiliary;
    }
    .item:hover {
      @include edu-color-auxiliary;
    }
    .item + .item {
      margin-left: 30px;
    }
  }
}
.shop-detail {
  margin-top: 18px;
  background-color: #ffffff;
  .title {
    font-size: 14px;
    font-weight: 400;
    color: $text-color-import;
    padding: 15px 30px;
    border-bottom: 1px solid #ebeef5;
  }
  .content {
    padding: 20px 30px;
    font-size: 14px;
    font-weight: 400;
    color: $text-color-import;
    line-height: 24px;
    letter-spacing: 1px;
    word-wrap: break-word;
    ::v-deep img {
      max-width: 100%;
    }
    ::v-deep * {
      margin: 0;
      padding: 0;
    }
  }
}
</style>
